package cn.ydt.ydt.shopping.webapi.service;


import cn.ydt.ydt.pojo.shopping.dto.SimpleVegetableDTO;
import cn.ydt.ydt.pojo.shopping.model.VegetableElastic;
import cn.ydt.ydt.pojo.shopping.vo.SimpleVegetableVO;
import cn.ydt.ydt.shopping.service.ISearchService;
import cn.ydt.ydt.shopping.service.IVegetableService;
import cn.ydt.ydt.shopping.webapi.repository.VegetableRepository;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@Slf4j
@SpringBootTest
public class testVegetable {
    @Autowired
    IVegetableService vegetableService;

    @Autowired
    ISearchService service;

    @Autowired
    VegetableRepository repository;

    //测试根据类别查询菜品列表
    @Test
    void getVegetableList(){
        String sort = "蔬菜";
        List<SimpleVegetableVO> list = vegetableService.getVegetableService(sort);
        log.info("查询出来的菜品为:{}"+list);
    }

    //测试插入购物车信息
    @Test
    void addVegetableCart(){
        SimpleVegetableDTO simpleVegetableDTO = new SimpleVegetableDTO();
        simpleVegetableDTO.setVegetableName("白菜");
        simpleVegetableDTO.setCartCount(15);
        vegetableService.addVegetableCart(simpleVegetableDTO);
    }


    //测试es
    @Test
    void testEs(){
        repository.deleteAll();
        service.loadVegetable();
        Iterable<VegetableElastic> es = repository.findAll();
        es.forEach(e-> System.out.println(e));
    }


}
